'use strict';

const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Banner = app.model.define('banner', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    name: {
      type: STRING(30),
      allowNull: false,
      unique: true,
      comment: 'banner名称',
    },
    path: {
      type: STRING(255),
      allowNull: false,
      comment: 'banner路径',
    },
    sort: {
      type: INTEGER,
      allowNull: false,
      comment: '排序',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      comment: '状态',
    },
    create_time: {
      type: DATE,
      get() {
        return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    updated_time: {
      type: DATE,
      get() {
        return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    }
  }, {
    tableName: 'banner',
    timestamps: true,
    comment: 'banner表',
    createdAt: 'create_time',
    updatedAt: 'updated_time'
  });

  return Banner;
};

// 根据以上字段生成mysql建表语句

// CREATE TABLE `banner` (
//   `id` int(11) NOT NULL AUTO_INCREMENT,
//   `name` varchar(30) NOT NULL,
//   `path` varchar(255) NOT NULL,
//   `sort` int(11) NOT NULL,
//   `status` int(11) NOT NULL,
//   `create_time` datetime NOT NULL,
//   `updated_time` datetime NOT NULL,
//   PRIMARY KEY (`id`)
// ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='banner表';
